package main

import "fmt"

func quickSort(arr *[]int, start int, end int){
	//midIndex := len(arr) / 2
	//mid := arr[midIndex]
	mid := (*arr)[start]

	left := start
	right := end

	if start >= end {
		return
	}

	for left < right{
		if left >= right {
			break
		}
		for left < right && (*arr)[right] >= mid{
			right -= 1
		}
		(*arr)[left] = (*arr)[right]
		for left < right && (*arr)[left] < mid{
			left += 1
		}
		(*arr)[right] = (*arr)[left]
	}
	(*arr)[left] = mid

	quickSort(arr, start, left-1)
	quickSort(arr, left+1, end)
}


func main(){
	arr := []int{12, 6, 7, 23, 4, 9, 27}
	quickSort(&arr, 0, len(arr)-1)
	fmt.Println(arr)
}
